<?php
return [
    //app 在 worker 里面加载
    'app' => [
        'loader' => [
            'paths' => [
                'Core\\' => SWOOLE_PATH.'/Core/',
            ],
        ],
        'domains' => [
            '192.168.204.132:8080' => [
                'demo\\', //namespace
                SWOOLE_PATH.'/demo/',//document root
                [
                    //session 配置
//                    'session.key' => 'test',
//                    'session.table' => 'swoole_session',
                ],//param
            ],
        ],
        'db' => [
            //数据库配置
//            'test' => [
//                'dsn' => 'mysql:dbname=userhome;port=3306;host=127.0.0.1',
//                'username' => 'root',
//                'password' => 'root',
//                'charset' => 'utf8',
//                'option' =>  array(\PDO::ATTR_PERSISTENT => true, \PDO::ATTR_AUTOCOMMIT => 1),
//                'timeout' => 600,//连接保持的时间
//            ]
        ],
    ],
    //全局加载
    'swoole' => [
        'max_request' => 0,
        'worker_num' => 4,
        //'task_worker_num' => 4,
    ],
    'server' => [
        [
            'id' => 1,
            'ip' => '0.0.0.0',
            'port' => 8080,
            'mode' => SWOOLE_PROCESS,
            'sock_type' => SWOOLE_SOCK_TCP,
            'class' => swoole_http_server::class,
            'swoole' => [
                'document_root' => SWOOLE_PATH.'/../public',
                'enable_static_handler' => false,
            ],
            'on' => [
                'WorkerStart' => function (swoole_http_server $server, $workerId)
                {
                    swoole_set_process_name('HttpServer worker process '.$workerId);
                    echo date('Y-m-d H:i:s')." worker start id:{$workerId} \r\n";
                    $config = getConfig();
                    \Core\Server::Instance()->appConfig = $config['app'];
                    \Core\Loader::Instance()->paths =  \Core\Server::Instance()->appConfig['loader']['paths'];
                    unset($config);
                    return true;
                },
                'task' => function (swoole_http_server $serv,  $task_id,  $src_worker_id, $data)
                {

                },
                'finish' => function(swoole_server $serv,  $task_id,  $data)
                {
                    var_dump("onFinish:",$data);
                },
                'request' => function (swoole_http_request $request,swoole_http_response $response) {
                    \Core\Handler\Http::Instance()->handle($request,$response);
                },

            ],
        ],
    ],
];